import pandas as pd
import random

# 读取本地Excel文件
df = pd.read_excel("题库.xlsx")

# 随机打乱题目顺序
df = df.sample(frac=1)

# 遍历题目并生成随机答案
for index, row in df.iterrows():
    print(row["题目"])
    options = [row["选项1"], row["选项2"], row["选项3"], row["选项4"]]
    random.shuffle(options)
    for i in range(4):
        print(chr(ord('A')+i) + ". " + options[i])
    answer = chr(ord('A') + options.index(row["答案"]))
    print("答案：" + answer)